﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.Objects;

namespace Sample.LINQ
{
  /// <summary>
  /// Interaction logic for WinEntityFx.xaml
  /// </summary>
  public partial class WinEntityFx : Window
  {
    private IpdTestEntities myEntities;

    public WinEntityFx()
    {
      InitializeComponent();

      myEntities = new IpdTestEntities();

      try
      {
        var query =
          from m in myEntities.Machine
          orderby m.Name
          select m;

        //Liaison de la comboBox à la DB
        this.cmbEntityFx.DisplayMemberPath = "Name";
        var result = ((ObjectQuery)query).Execute(MergeOption.AppendOnly);
        /*foreach (Machine item in result)
        {
          this.cmbEntityFx.Items.Add(item);
        }*/
        this.cmbEntityFx.ItemsSource = result;
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }
  }
}
